from backtesting import Backtest, Strategy
from backtesting.lib import crossover

from backtesting.test import SIMA, GOOG


class SmaCross(Strategy):

    def init(self):
        price = self.data.Close
        self.ma1 = self.I(SIMA, price, 10)
        self.ma2 = self.I(SIMA, price, 20)

    def next(self):
        if crossover(self.ma1, self.ma2):
            print(crossover(self.ma1, self.ma2))
            self.buy()
        elif crossover(self.ma2, self.ma1):
            self.sell()

print(type(GOOG.index[0]))
bt = Backtest(GOOG, SmaCross, cash=50_000,commission=.0013,exclusive_orders=True)
stats = bt.run()
bt.plot()